#!usr/bin/python3
import sys
import getopt
import os
import shutil

"""
必须两参数
1、原始路径（包含图片文件的文件夹路径）
2、需要将结果写入到指定文件的路径
递归读取指定目录下的图片文并写入
"""
def main(argv):
    originPath = argv[0]  # 原始路径
    targetPath = argv[1]  # 目标路径
    print("打开路径", originPath)
    print("存储路径", targetPath)

    targetFile = open(targetPath, "w")
    print("dafalksfj")
    for dirpath, dirnames, filenames in os.walk(originPath):
        for file in filenames:
            if os.path.splitext(file)[1] in [".java",".kt"]:
                currentPath = os.path.join(dirpath, file)
                print("读取到的java文件为",currentPath)
                for line in open(currentPath):
                    startIndex = len(line) - len(line.lstrip())
                    if (line[startIndex:startIndex + 2] in ["//", "/*", "* "]) or (line[startIndex:startIndex+1] in ["*"]):
                        continue
                    else:
                        targetFile.write(line)

    targetFile.close()


if __name__ == "__main__":
    main(sys.argv[1:])
